<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台用户添加</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__ADMIN__css/bootstrap.min.css" rel="stylesheet">
    <link href="__ADMIN__css/font-awesome.min.css" rel="stylesheet">
    <link href="__ADMIN__css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__ADMIN__css/animate.css" rel="stylesheet">
    <link href="__ADMIN__css/style.css" rel="stylesheet">
    <link href="__ADMIN__js/plugins/layer/skin/default/layer.css" rel="stylesheet">
    <link href="__ADMIN__css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="__ADMIN__css/plugins/switchery/switchery.css" rel="stylesheet">
    <style>
        .btnsub{border:0;outline:0;width: 100px;height:36px;background-color: #05ad94;color:#fff;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <form action="{:U('Group/rule')}" method="post" id="forma">
        <input type="hidden" name="id" value="{$id}">
        <div class="col-sm-13">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                <foreach name="datalist" item="vs">
                    <div class="row">
                        <label class="checkbox-inline">
                            <input type="checkbox" name="rule_ids[]" value="{$vs['id']}" onclick="checkAll(this)" {$rule[0]} style="position: relative; top:14px; left: 3px;" <if condition="in_array($vs['id'],$rule)">checked</if>>
                        <h4 style="margin-top: -3px">{$vs['title']}</h4></label>
                        <div class="hr-line-dashed" style="margin-top: -3px;margin-bottom:10px;"></div>
                        <notempty name="vs['_child']">

                        <foreach name="vs['_child']" item="vso">
                        <div class="col-sm-13" style="padding-left: 0px;font-size: 12px;">
                            <table class="table table-striped table-bordered table-hover table-condensed">
                                <tr class="b-group">
                                    <th width="10%"><label>{$vso['title']}&nbsp;&nbsp;
                                    <input type="checkbox" name="rule_ids[]" value="{$vso['id']}" onclick="checkAlls(this)" <if condition="in_array($vso['id'],$rule)">checked</if>>
                                    </label></th>
                                    <notempty name="vso['_child']">

                                        <td>

                                            <foreach name="vso['_child']" item="va">
                                                <label>&nbsp;&nbsp;{$va['title']}&nbsp;&nbsp;<input type="checkbox" name="rule_ids[]" value="{$va['id']}" <if condition="in_array($va['id'],$rule)">checked</if>></label>
                                            </foreach>

                                        </td>

                                    </notempty>
                                </tr>
                            </table>
                        </div>
                        </foreach>

                        </notempty>
                        </div>
                    </foreach>
                    <input type="submit" id="submit" name="submit" value="提交" class="btnsub">
                </div>
            </div>
        </div>
    </form>
</div>
<script src="__ADMIN__js/jquery.min.js"></script>
<script src="__ADMIN__js/bootstrap.min.js"></script>
<script src="__ADMIN__js/plugins/layer/layer.js"></script>
<script src="__ADMIN__js/comment.js"></script>
<script>
    $(function(){
       $('#submit').click(function(){
            var forma = new FormData (document.getElementById('forma'));
            $.ajax({
                url:$('#forma').prop('action'),
                type:'post',
                data:forma,
                dataType:'json',
                cache:false,
                processData:false,
                contentType:false,
                success:function(data){
                    if(data.status < 1){
                        comment.error(data.mess);
                    }else{
                        comment.success(data.mess,"{:U('Group/rule?id='.$id)}");
                    }
                }
            });
            return false;
       });
    });
    //全选check
    function checkAll(obj){
        $(obj).parents('.row').eq(0).find("input[type='checkbox']").prop('checked',$(obj).prop('checked'));//prop追加属性
    }
    function checkAlls(obj){
        $(obj).parents('.b-group').eq(0).find("input[type='checkbox']").prop('checked',$(obj).prop('checked'));
    }
</script>
</body>
</html>
